package com.example.mybatisdemo.Mapper;

import com.example.mybatisdemo.model.UserInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {
    @Results(id="mybatis", value = {
            @Result(column = "delete_flag", property = "deleteFlag"),
            @Result(column = "create_time", property = "createTime"),
            @Result(column = "update_time", property = "updateTime")
    })
    @Select("select * from userinfo")
    List<UserInfo> queryList();
    @ResultMap(value = "mybatis")
    @Select("select * from userinfo where id = #{id}")
    UserInfo query(Integer id);

    @Select("select * from userinfo where id = #{id} and age = #{b}")
    UserInfo queryByID(@Param("id") Integer a, @Param("b") Integer b);

    @Insert("insert into userinfo(username, password, age, gender, phone)"+
    "values (#{username}, #{password}, #{age}, #{gender}, #{phone})")
    Integer insert(UserInfo userInfo);
    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into userinfo(username, password, age, gender, phone)"+
            "values (#{userInfo.username}, #{userInfo.password}, #{userInfo.age}, #{userInfo.gender}, #{userInfo.phone})")
    Integer insertByParam(@Param("userInfo") UserInfo userInfo);

    @Delete("delete from userinfo where id = #{id}")
    Integer delete(Integer id);

    @Update("update userinfo set username = #{name} where id = #{id}")
    Integer update(@Param("name") String username, @Param("id") Integer id);

    @Select("select * from userinfo where username like '%${name}%' ")
    List<UserInfo> queryList2(@Param("name") String name);

    @Select("select * from userinfo where username like concat('%',#{name},'%') ")
    List<UserInfo> queryList3(@Param("name") String name);


}

